import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/fonts/iconfont.css'
import './assets/global.css'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'
import moment from 'moment'
// 导入富文本编辑器和对应样式
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 导入路由进度条依赖项和相应样式
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
// 配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 配置请求拦截器，在请求头中用Authorization字段给api提供token令牌
axios.interceptors.request.use(config => {
  // 当发起请求的时候展示进度条 Nprogress.start()
  Nprogress.start()
  // 为每一次请求挂载token令牌
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
axios.interceptors.response.use(config => {
  // 当响应成功的时候隐藏进度条 Nprogress.done()
  Nprogress.done()
  return config
})
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.component('tree-table', TreeTable)
// 将富文本编辑器设置为全局组件
Vue.use(VueQuillEditor)
// 时间过滤器
Vue.filter('time', function (value, formatString) {
  formatString = formatString || 'YYYY-MM-DD HH:mm'
  return moment(value).format(formatString)
})
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
